home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Examples / DrawShapes / UBetterFeedbackCmd.inc1.p < prev    next >
Encoding:
Text File  |  1990-10-25  |  6.3 KB  |  219 lines  |  [TEXT/MPS ]

  1. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n+]}
  2. { UBetterFeedbackCmd.inc1.p }
  3. { Copyright © 1988-1990 by Apple Computer, Inc. All rights reserved.}
  4.  
  5. {--------------------------------------------------------------------------------------------------}
  6.  
  7. TYPE
  8.     QElemWithA5AndCounterPtr = ^QElemWithA5AndCounter;
  9.     QElemWithA5AndCounter = RECORD
  10.         OldA5:                Longint;                    { A place to store the old value of A5 since
  11.                                                          when debugging the compiler trashes the
  12.                                                          value of A0 for any locals in the VBL task
  13.                                                          thus making the pointer to the
  14.                                                          paramblockrec unavailable }
  15.         A5:                 Longint;                    { The value of A5 will be stored here to be
  16.                                                          available at VBL time }
  17.         q:                    QElem;                        { our VBL queue element }
  18.         END;
  19.  
  20. {--------------------------------------------------------------------------------------------------}
  21.  
  22. VAR
  23.     gCounter:            Longint;                        { our counter incremented in the VBL task }
  24.     gOurVBLTask:        QElemWithA5AndCounter;            { our VBL task record }
  25.     gSlot:                INTEGER;                        { the slot our VBL is installed in }
  26.  
  27. {--------------------------------------------------------------------------------------------------}
  28. {$Push} {$IFC qTrace} {$D+} {$ENDC}
  29. {$W+}
  30. {$R-}
  31. {$Init-}
  32. {$OV-}
  33. {$S ARes}    { NOTE: must be resident! We *don't* want a segment load at interrupt time. }
  34.  
  35. PROCEDURE IncOurVBLCounter;
  36. { our VBL task that increments the counter which is tested in WaitBetterFeedback }
  37.  
  38.     CONST
  39.         theOffset            = sizeof(Longint) * 2;
  40.     
  41.     BEGIN
  42.     gOurVBLTask.OldA5 := SetA5(QElemWithA5AndCounterPtr(GetParmBlockPtr - theOffset)^.A5);
  43.  
  44.     WITH gOurVBLTask DO
  45.         BEGIN
  46.         q.vblQElem.vblCount := 1;                        { reprime the pump }
  47.  
  48.         gCounter := gCounter + 1;                        { increment our counter }
  49.  
  50.         IF SetA5(OldA5) = 0 THEN;                        { must discard the function result because
  51.                                                          when A5 gets reset we have no place to put
  52.                                                          the result }
  53.         END;
  54.     END;
  55. {$Pop}
  56.  
  57. {--------------------------------------------------------------------------------------------------}
  58. {$S ADoCommand}
  59.  
  60. PROCEDURE InstallOurVBL(aView: TView);
  61.  
  62. { install a VBL task to increment a counter - used by TShapeCommand's TrackFeedback method }
  63.  
  64.     FUNCTION GetAVideoSlot:INTEGER;
  65.     
  66.     { return the video slot associated with the view's port }
  67.  
  68.         VAR
  69.             aWindow:        TWindow;
  70.             aDefVideoRec:    DefVideoRec;
  71.             aGDHandle:        GDHandle;
  72.             aRect:            Rect;
  73.             aAuxDCEHandle:    AuxDCEHandle;
  74.  
  75.         BEGIN
  76.         aWindow := aView.GetWindow;
  77.         IF (aWindow = NIL) THEN
  78.             BEGIN
  79.             GetVideoDefault(@aDefVideoRec);
  80.             GetAVideoSlot := aDefVideoRec.sdSlot;
  81.             END
  82.         ELSE
  83.             BEGIN
  84.             aGDHandle := aWindow.GetMaxIntersectedDevice(aRect);
  85.             aAuxDCEHandle := AuxDCEHandle(GetDCtlEntry(aGDHandle^^.gdRefNum));
  86.             GetAVideoSlot := aAuxDCEHandle^^.dCtlSlot;
  87.             END
  88.         END;
  89.  
  90.     BEGIN
  91.     gCounter := 0;
  92.     WITH gOurVBLTask.q.vblQElem DO
  93.         BEGIN
  94.         qType := ORD(vType);
  95.         vblAddr := @IncOurVBLCounter;
  96.         vblCount := 1;
  97.         vblPhase := 0;
  98.         END;
  99.     gOurVBLTask.A5 := Longint(GetA5);
  100.     IF TrapExists(_SlotVInstall) THEN
  101.         BEGIN
  102.         gSlot := GetAVideoSlot;
  103.         FailOSErr(SlotVInstall(@gOurVBLTask.q, gSlot));
  104.         END
  105.     ELSE
  106.         FailOSErr(VInstall(@gOurVBLTask.q));
  107.     END;
  108.  
  109. {--------------------------------------------------------------------------------------------------}
  110. {$S ADoCommand}
  111.  
  112. PROCEDURE RemoveOurVBL;
  113.  
  114. { remove the VBL task we installed }
  115.  
  116.     BEGIN
  117.     IF TrapExists(_SlotVRemove) THEN
  118.         FailOSErr(SlotVRemove(@gOurVBLTask.q, gSlot))
  119.     ELSE
  120.         FailOSErr(VRemove(@gOurVBLTask.q));
  121.     END;
  122.  
  123. {--------------------------------------------------------------------------------------------------}
  124. {$S ASelCommand}
  125.  
  126. PROCEDURE TBetterFeedbackCmd.IBetterFeedbackCmd(itsCmdNumber: CmdNumber; itsDocument: TDocument;
  127.                                                 itsView: TView; itsScroller: TScroller;
  128.                                                 betterFeedbackDesired: BOOLEAN);
  129.  
  130.     BEGIN
  131.     ICommand(itsCmdNumber, itsDocument, itsView, itsScroller);
  132.     fBetterFeedbackInstalled := NOT kInstall;
  133.     fBetterFeedbackDesired := betterFeedbackDesired;
  134.     END;
  135.  
  136. {--------------------------------------------------------------------------------------------------}
  137. {$S ADoCommand}
  138.  
  139. PROCEDURE TBetterFeedbackCmd.Free; OVERRIDE;
  140.  
  141.     BEGIN
  142.     BetterFeedback(NOT kInstall);
  143.     INHERITED Free;
  144.     END;
  145.  
  146. {--------------------------------------------------------------------------------------------------}
  147. {$S ADoCommand}
  148.  
  149. FUNCTION TBetterFeedbackCmd.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint, previousPoint,
  150.                                         nextPoint: VPoint;
  151.                                         mouseDidMove: Boolean): TCommand; OVERRIDE;
  152.  
  153.     BEGIN
  154.     IF aTrackPhase = trackRelease THEN
  155.         BetterFeedback(NOT kInstall);
  156.     TrackMouse := SELF;
  157.     END;
  158.  
  159. {--------------------------------------------------------------------------------------------------}
  160. {$S ADoCommand}
  161.  
  162. PROCEDURE TBetterFeedbackCmd.TrackFeedback(anchorPoint, nextPoint: VPoint; turnItOn,
  163.                                            mouseDidMove: Boolean);
  164.  
  165.     BEGIN
  166.     WaitBetterFeedback;
  167.     END;
  168.  
  169. {--------------------------------------------------------------------------------------------------}
  170. {$S ADoCommand}
  171.  
  172. PROCEDURE TBetterFeedbackCmd.BetterFeedback(install: BOOLEAN);
  173.  
  174. { use a VBL to improve TrackFeedback; eventually, this should go in TApplication.TrackMouse }
  175.  
  176.     BEGIN
  177.     IF (fBetterFeedbackDesired = kBetterFeedbackDesired) THEN
  178.         BEGIN
  179.         IF (install = kInstall) & (fBetterFeedbackInstalled = NOT kInstall) THEN
  180.             InstallOurVBL(fView)
  181.         ELSE IF (install = NOT kInstall) & (fBetterFeedbackInstalled = kInstall) THEN
  182.             RemoveOurVBL;
  183.         fBetterFeedbackInstalled := install;
  184.         END;
  185.     END;
  186.  
  187. {--------------------------------------------------------------------------------------------------}
  188. {$S MADoCommand}
  189.  
  190. PROCEDURE TBetterFeedbackCmd.WaitBetterFeedback;
  191. { WaitBetterFeedback waits for our counter to change value }
  192.  
  193.     VAR
  194.         t:    Longint;
  195.  
  196.     BEGIN
  197.     IF (fBetterFeedbackDesired = kBetterFeedbackDesired) THEN
  198.         BEGIN
  199.         IF (fBetterFeedbackInstalled = NOT kInstall) THEN
  200.             BetterFeedback(kInstall);
  201.         t := gCounter;                                    { we'll wait til screen refresh }
  202.         REPEAT UNTIL t <> gCounter;                        { let's hope this changes soon }
  203.         END;
  204.     END; {WaitBetterFeedback}
  205.  
  206. {--------------------------------------------------------------------------------------------------}
  207. {$S AFields}
  208.  
  209. PROCEDURE TBetterFeedbackCmd.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  210.                                                    fieldType: INTEGER)); OVERRIDE;
  211.     
  212.     BEGIN
  213.     DoToField('TBetterFeedbackCmd', NIL, bClass);
  214.     DoToField('fBetterFeedbackInstalled', @fBetterFeedbackInstalled, bBoolean);
  215.     DoToField('fBetterFeedbackDesired', @fBetterFeedbackDesired, bBoolean);
  216.     INHERITED Fields(DoToField);
  217.     END;
  218.  
  219.